package com.itguigu.fruit.demo;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

public class demo01 {
    public static void main(String[] args) {
        String driver = "com.mysql.jdbc.Driver";

        String url = "jdbc:mysql://localhost:3306/db_pss";

        String user = "root";

        String password = "123456";

        try {

// 加载驱动

            Class.forName(driver);

// 获取数据库连接

            Connection conn = DriverManager.getConnection(url, user, password);

// 创建Statement对象

            Statement stmt = conn.createStatement();

// 执行查询

            ResultSet rs = stmt.executeQuery("SELECT * FROM pill_factory");

// 处理查询结果

            while (rs.next()) {

                int id = rs.getInt("factory_id");

                String name = rs.getString("factory_name");

                System.out.println("id：" + id + "，姓名：" + name);

            }

// 关闭资源

            rs.close();

            stmt.close();

            conn.close();

        } catch (ClassNotFoundException e) {

            e.printStackTrace();

        } catch (SQLException e) {

            e.printStackTrace();

        }
    }
}
